home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / nrdump.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  5KB  |  242 lines

  1. /* NET/ROM header tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "netrom.h"
  8. #include "nr4.h"
  9. #include "trace.h"
  10.  
  11. /* Display NET/ROM network and transport headers */
  12. void
  13. #ifdef MONITOR
  14. netrom_dump(fp,bpp,check,mon)
  15. int mon;
  16. #else
  17. netrom_dump(fp,bpp,check)
  18. #endif
  19. FILE *fp;
  20. struct mbuf **bpp;
  21. int check;
  22. {
  23.     char src[AXALEN],dest[AXALEN];
  24.     char tmp[AXBUF];
  25.     char thdr[NR4MINHDR];
  26.     register i;
  27. #ifdef MONITOR
  28.     register int j;
  29. #endif
  30.  
  31.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  32.         return;
  33.     /* See if it is a routing broadcast */
  34.     if(uchar(*(*bpp)->data) == NR3NODESIG) {
  35.         (void)PULLCHAR(bpp);        /* Signature */
  36.         pullup(bpp,tmp,ALEN);
  37.         tmp[ALEN] = '\0';
  38. #ifdef MONITOR
  39.         if (mon)
  40.             fprintf(fp, "NR ROUTE %s\n", tmp);
  41.         else
  42. #endif
  43.         fprintf(fp,"NET/ROM Routing: %s\n",tmp);
  44.         for(i = 0;i < NRDESTPERPACK;i++) {
  45.             if (pullup(bpp,src,AXALEN) < AXALEN)
  46.                 break;
  47. #ifndef MONITOR
  48.             fprintf(fp,"        %12s",pax25(tmp,src));
  49. #endif
  50.             pullup(bpp,tmp,ALEN);
  51.             tmp[ALEN] = '\0';
  52. #ifdef MONITOR
  53.             if (mon)
  54.             {
  55.                 for (j = 0; tmp[j] && tmp[j] != ' '; j++)
  56.                 ;
  57.                 tmp[j] = '\0';
  58.                 fprintf(fp, "%6s:", tmp);
  59.                 fprintf(fp, "%-9s ", pax25(tmp, src));
  60.             }
  61.             else
  62. #endif
  63.             fprintf(fp,"%8s",tmp);
  64.             pullup(bpp,src,AXALEN);
  65. #ifdef MONITOR
  66.             if (mon)
  67.                 fprintf(fp, "%-9s ", pax25(tmp, src));
  68.             else
  69. #endif
  70.             fprintf(fp,"    %12s",pax25(tmp,src));
  71.             tmp[0] = PULLCHAR(bpp);
  72. #ifdef MONITOR
  73.             if (mon)
  74.             {
  75.                 fprintf(fp, "%-3u%s", uchar(tmp[0]),
  76.                     (i & 1? "\n": "        "));
  77.             }
  78.             else
  79. #endif
  80.             fprintf(fp,"    %3u\n",uchar(tmp[0]));
  81.         }
  82. #ifdef MONITOR
  83.         if (mon && (i & 1))
  84.             fprintf(fp, "\n");
  85. #endif
  86.         return;
  87.     }
  88.     /* See if it is a routing poll - WG7J */
  89.     if(uchar(*(*bpp)->data) == NR3POLLSIG) {
  90.         (void)PULLCHAR(bpp);        /* Signature */
  91.         pullup(bpp,tmp,ALEN);
  92.         tmp[ALEN] = '\0';
  93. #ifdef MONITOR
  94.     if (mon)
  95.         fprintf(fp, "NR POLL %s\n", tmp);
  96.     else
  97. #endif
  98.         fprintf(fp,"NET/ROM Poll: %s\n",tmp);
  99.         return;
  100.     }
  101.     /* Decode network layer */
  102.     pullup(bpp,src,AXALEN);
  103. #ifdef MONITOR
  104.     if (mon)
  105.         fprintf(fp, "NR %s", pax25(tmp, src));
  106.     else
  107. #endif
  108.     fprintf(fp,"NET/ROM: %s",pax25(tmp,src));
  109.  
  110.     pullup(bpp,dest,AXALEN);
  111.     fprintf(fp,"->%s",pax25(tmp,dest));
  112.  
  113.     i = PULLCHAR(bpp);
  114. #ifdef MONITOR
  115.     if (!mon)
  116. #endif
  117.     fprintf(fp," ttl %d\n",i);
  118.  
  119.     /* Read first five bytes of "transport" header */
  120.     pullup(bpp,thdr,NR4MINHDR);
  121.     switch(thdr[4] & NR4OPCODE){
  122.      case NR4OPPID:    /* network PID extension */
  123.         if (thdr[0] == NRPROTO_IP && thdr[1] == NRPROTO_IP) {
  124. #ifdef MONITOR
  125.             if (mon)
  126.                 fprintf(fp, " IP ");
  127.              ip_dump(fp,bpp,check,mon);
  128. #else
  129.              ip_dump(fp,bpp,check) ;
  130. #endif
  131.             return;
  132.         }
  133.          else
  134. #ifdef MONITOR
  135.             if (mon)
  136.                 fprintf(fp, " %x/%x\n",
  137.                        uchar(thdr[0]), uchar(thdr[1]));
  138.             else
  139. #endif
  140.              fprintf(fp,"         protocol family %x, proto %x",
  141.              uchar(thdr[0]), uchar(thdr[1])) ;
  142.          break ;
  143.     case NR4OPCONRQ:    /* Connect request */
  144. #ifdef MONITOR
  145.         if (mon)
  146.             fprintf(fp, " conn %d/%d", uchar(thdr[0]), uchar(thdr[1]));
  147.         else
  148. #endif
  149.         fprintf(fp,"         conn rqst: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  150.         i = PULLCHAR(bpp);
  151. #ifdef MONITOR
  152.         if (!mon)
  153. #endif
  154.         fprintf(fp," wnd %d",i);
  155.         pullup(bpp,src,AXALEN);
  156.         fprintf(fp," %s",pax25(tmp,src));
  157.         pullup(bpp,dest,AXALEN);
  158.         fprintf(fp,"@%s",pax25(tmp,dest));
  159.         break;
  160.     case NR4OPCONAK:    /* Connect acknowledgement */
  161. #ifdef MONITOR
  162.         if (mon)
  163.             fprintf(fp, " c-ack %d/%d->%d/%d",
  164.                    uchar(thdr[0]), uchar(thdr[1]),
  165.                    uchar(thdr[2]), uchar(thdr[3]));
  166.         else
  167. #endif
  168.         fprintf(fp,"         conn ack: ur ckt %d/%d my ckt %d/%d",
  169.          uchar(thdr[0]), uchar(thdr[1]), uchar(thdr[2]),
  170.          uchar(thdr[3]));
  171.         i = PULLCHAR(bpp);
  172. #ifdef MONITOR
  173.         if (!mon)
  174. #endif
  175.         fprintf(fp," wnd %d",i);
  176.         break;
  177.     case NR4OPDISRQ:    /* Disconnect request */
  178. #ifdef MONITOR
  179.         if (mon)
  180.             fprintf(fp, " disc %d/%d",
  181.                    uchar(thdr[0]), uchar(thdr[1]));
  182.         else
  183. #endif
  184.         fprintf(fp,"         disc: ckt %d/%d",
  185.          uchar(thdr[0]),uchar(thdr[1]));
  186.         break;
  187.     case NR4OPDISAK:    /* Disconnect acknowledgement */
  188. #ifdef MONITOR
  189.         if (mon)
  190.             fprintf(fp, " d-ack %d/%d", uchar(thdr[0]),
  191.                    uchar(thdr[1]));
  192.         else
  193. #endif
  194.         fprintf(fp,"         disc ack: ckt %d/%d",
  195.          uchar(thdr[0]),uchar(thdr[1]));
  196.         break;
  197.     case NR4OPINFO:    /* Information (data) */
  198. #ifdef MONITOR
  199.         if (mon)
  200.             fprintf(fp, " %d/%d", uchar(thdr[0]),
  201.                    uchar(thdr[1]));
  202.         else
  203.         {
  204. #endif
  205.         fprintf(fp,"         info: ckt %d/%d",
  206.          uchar(thdr[0]),uchar(thdr[1]));
  207.         fprintf(fp," txseq %d rxseq %d",
  208.          uchar(thdr[2]), uchar(thdr[3]));
  209. #ifdef MONITOR
  210.         }
  211. #endif        
  212.         break;
  213.     case NR4OPACK:    /* Information acknowledgement */
  214. #ifdef MONITOR
  215.         if (mon)
  216.             fprintf(fp, " ack %d/%d",
  217.                    uchar(thdr[0]), uchar(thdr[1]));
  218.         else
  219.         {
  220. #endif
  221.         fprintf(fp,"         info ack: ckt %d/%d",
  222.          uchar(thdr[0]),uchar(thdr[1]));
  223.         fprintf(fp," txseq %d rxseq %d",
  224.          uchar(thdr[2]), uchar(thdr[3]));
  225. #ifdef MONITOR
  226.         }
  227. #endif
  228.         break;
  229.     default:
  230.          fprintf(fp,"         unknown transport type %d",
  231.          thdr[4] & 0x0f) ;
  232.         break;
  233.     }
  234.     if(thdr[4] & NR4CHOKE)
  235.         fprintf(fp," CHOKE");
  236.     if(thdr[4] & NR4NAK)
  237.         fprintf(fp," NAK");
  238.     if(thdr[4] & NR4MORE)
  239.         fprintf(fp," MORE");
  240.     fprintf(fp,"\n");
  241. }
  242.